﻿using HHG.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnLineExam.Web.mag
{
	public partial class examInfo : System.Web.UI.Page
	{
		protected ExamInfo PaperExamInfo { get; set; }
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{

				GetData();
			}

		}
		protected void GetData() {


			var paperId = Request.QueryString["id"].GetInt();

			using (var ctx = new OnLineExam.Data.OnlineExamEntities())
			{
				var paper = ctx.Paper.AsNoTracking().First(s => s.PaperID == paperId);
				var userAnswers = ctx.UserAnswer.Where(s => s.PaperID == paperId).ToList();


				var want2ExamUsers = paper.joinemps.Split(',').ToList();

				//分组 找出已经考试的人
				 

				var notexamUserAnswers = want2ExamUsers.Where(s=>!userAnswers.Any(a=>a.UserID==s)).ToList();

				var notExamUserNames = ctx.Users.Where(s => notexamUserAnswers.Contains(s.UserID)).Select(s=>s.UserName).ToList();

				double percent = double.Parse( notexamUserAnswers.Count()+"") / double.Parse(want2ExamUsers.Count() + "");


				this.PaperExamInfo = new ExamInfo(paperId, percent, notExamUserNames);

			 
			}
		}

		protected class ExamInfo
		{
			public int PaperId { get; set; }

			public double Percent { get; set; }
			public string PercentStr {
				get
				{
					return (this.Percent * 100) + "%";
				}
			 }

			public List<string> NotExamUsers { get; set; }

			public ExamInfo(int paperId, double percent, List<string> notExamUsers)
			{
				this.PaperId = paperId;
				this.Percent = percent;
				this.NotExamUsers = notExamUsers;
			}
		}

	}
}